public OnPlayerDeath(playerid, killerid, reason) {
	// Crashsafe skin sync
	CPlayer::crashSafeSkinSync(playerid);
	
	// If someone spectates the player, we have to abort this.
	loop_players(i) {
		if (playerData[i][spectateId] == playerid)
			CPlayer::Unspectate(i);
	}
	
	// Player is wasted.
	playerData[playerid][isSpawned] = false;
	
	// That will style his screen while he is viewing his dead body.
	CPlayer::HideTextDraws(playerid);
	CPlayer::HideLobbyDraws(playerid);
	
	// There is no killer, the player killed himself.
	if (!IsPlayerConnected(killerid)) {
		if (playerData[playerid][isPlaying] || playerData[playerid][isDuel] || playerData[playerid][activeDM] > -1)
			SendDeathMessage(INVALID_PLAYER_ID, playerid, reason);
		
		if (playerData[playerid][isPlaying]) {
			playerData[playerid][isPlaying] = false;
			
			if (playerData[playerid][team] == TEAM_HOME) 
				gameData[iPlayingHome]--;
				
			if (playerData[playerid][team] == TEAM_AWAY) 
				gameData[iPlayingAway]--;
			
            CBase::CheckActivePlayers();
			DisablePlayerCheckpoint(playerid);
			RemovePlayerMapIcon(playerid, BASE_ICON_ID);
		}
		
		// And we stop here.
		return true;
	}
	
    // This will play a nice sound for the killer.
    PlayerPlaySound(killerid, 5449, 0.0, 0.0, 0.0);
    
    
	// We will set the player's camera to the killers position here.
    new Float: positionX, Float: positionY, Float: positionZ;
	GetPlayerPos(playerid, positionX, positionY, positionZ);
	SetPlayerCameraPos(playerid, positionX, positionY, positionZ);
	GetPlayerPos(killerid, positionX, positionY, positionZ);
	SetPlayerCameraLookAt(playerid, positionX, positionY, positionZ);
	
	// If the player has been killed in a base/duel/dm we will output some statistics here.
	if (playerData[killerid][isPlaying] == true || playerData[killerid][isDuel] == true || playerData[killerid][activeDM] > -1) {
		new Float: fDistance;
		new Float: fHealth_k;
		new Float: fArmour_k;
		new Float: pl_X[2];
		new Float: pl_Y[2];
		new Float: pl_Z[2];
		new iRandom_M = random(sizeof(deathVerbs));
		
        // We will output the death to the killbar.
		SendDeathMessage(killerid, playerid, reason);
        
		// We have to update the statistics here.
		playerData[playerid][deaths]++;
		playerData[killerid][kills]++;
			
		GetPlayerPos(playerid, pl_X[0], pl_Y[0], pl_Z[0]);
		GetPlayerPos(killerid, pl_X[1], pl_Y[1], pl_Z[1]);
			
		fDistance = betweenPoints(pl_X[0], pl_Y[0], pl_Z[0], pl_X[1], pl_Y[1], pl_Z[1]);
		GetPlayerHealth(killerid, fHealth_k);
		GetPlayerArmour(killerid, fArmour_k);
		
		SendFormattedMessage(playerid, C_LIGHTBLUE, "* You've been %s by %s (Weapon: %s | Distance: %.2f feet | Health left: %.2f)", deathVerbs[iRandom_M], CPlayer::getName(killerid), getWeaponNameEx(reason), fDistance, (fHealth_k + fArmour_k));
		SendFormattedMessage(killerid, C_LIGHTBLUE, "* You %s %s (Weapon: %s | Distance: %.2f feet | Health left: %.2f)", deathVerbs[iRandom_M], CPlayer::getName(playerid), getWeaponNameEx(reason), fDistance, (fHealth_k + fArmour_k));		
		SendFormattedMessageToAll(C_LIGHTBLUE, "* %s %s %s (Weapon: %s | Distance: %.2f feet | Health left: %.2f)", CPlayer::getName(killerid), deathVerbs[iRandom_M], CPlayer::getName(playerid), getWeaponNameEx(reason), fDistance, (fHealth_k + fArmour_k));	
		
		// If the killer is in a deathmatch we will restore his HP here.
		if (CDM::getPlayerDM(killerid) > -1) {
			SetPlayerHealth(killerid, 100.0);
			SetPlayerArmour(killerid, 100.0);
			SendClientMessage(killerid, C_YELLOW, "* Your armour and health have been restored because of your last kill.");
		}
		
		// If the killer is in a base we will check everything here.
		if (playerData[playerid][isPlaying] && !gameData[bIsArena]) {	
			RemovePlayerMapIcon(playerid, BASE_ICON_ID);
			CPlayer::checkRampage(killerid, playerid);
		
			// Add 1 kill to the killers's base kills.
			statsInfo[killerid][iSessionKills]++;
			statsInfo[killerid][iRoundKills]++;
			statsInfo[killerid][iCWKills]++;
			
			statsInfo[playerid][iSessionDeaths]++;
			statsInfo[playerid][iRoundDeaths]++;
			statsInfo[playerid][iCWDeaths]++;
			
			if (!gameData[bFirstBlood]) {
				CPlayer::triggerFirstBlood(killerid);
				gameData[bFirstBlood] = true;
			}
			
			// The dead player is not in a base anymore...
			playerData[playerid][isPlaying] = false;
		
			if (playerData[playerid][team] == TEAM_HOME) 
				gameData[iPlayingHome]--;
				
			if (playerData[playerid][team] == TEAM_AWAY) 
				gameData[iPlayingAway]--;
			
			CBase::CheckActivePlayers();
		}
		
        if (duelData[bIsRunning])
            CDuel::PlayerDeath(killerid, playerid);
		
		// Base/Duel/DM part ends here.
		SetPlayerColor(playerid, C_GREY);
		return true;
 	}
	
	SetPlayerColor(playerid, C_GREY);
	return true;
}